<template>
  <div class="navbar">
    <!-- 折叠 -->
    <Hamburger
      id="hamburger-container"
      :is-active="sidebar.opened"
      class="hamburger-container"
      @toggleClick="toggleSideBar"
    ></Hamburger>
    <!-- 面包屑 -->
    <breadcrumb class="breadcrumb-container"></breadcrumb>
    <!-- 右侧下拉菜单 -->
    <div class="right-menu">
      <header-search id="header-search" class="right-menu-item" />

      <screen-full id="screenfull" class="right-menu-item hover-effect" />
      <el-tooltip
        effect="dark"
        content="Global Size"
        placement="bottom"
      >
        <size-select id="size-select" class="right-menu-item hover-effect" />
      </el-tooltip>
      <el-dropdown class="avatar-container" trigger="click">
        <div class="avatar-wrapper" style="font-size:20px;">
          <img
            src="https://wpimg.wallstcn.com/f778738c-e4f8-4870-b634-56703b4acafe.gif?imageView2/1/w/80/h/80"
            class="user-avatar"
          />
          <i class="el-icon-caret-bottom"></i>
        </div>
        <template #dropdown>
          <el-dropdown-menu class="user-dropdown">
            <el-dropdown-item>
              <router-link to="/">首页</router-link>
            </el-dropdown-item>
            <el-dropdown-item>
              <a target="_blank" href="https://github.com/57code/vite2-in-action/">我的Github</a>
            </el-dropdown-item>
          </el-dropdown-menu>
        </template>
      </el-dropdown>
    </div>
  </div>
</template>
<script>
import { computed, defineComponent } from "vue"
import { useStore, mapGetters, mapState } from "vuex"
export default defineComponent({
  computed: {
    ...mapGetters(["sidebar", "avatar", "device"])
  }
})
</script>
<script setup>
import Breadcrumb from "./Breadcrumb.vue"
import Hamburger from "comps/hamburger/index.vue"
import HeaderSearch from "comps/header-search/index.vue"
import ScreenFull from "comps/common/screenfull/index.vue"
import SizeSelect from "comps/size-select/index.vue"

//  use mapGetters in 'script setup'
// const store = useStore()
// const sidebar = computed(
//   mapGetters(["sidebar"]).sidebar.bind({ $store: store })
// ).value
const store = useStore()
const toggleSideBar = function() {
  store.dispatch("app/toggleSideBar")
}
</script>
<style lang="scss" scoped>
.navbar {
  height: 50px;
  overflow: hidden;
  position: relative;
  background: #fff;
  box-shadow: 0 1px 4px rgba(0, 21, 41, 0.08);
  .hamburger-container {
    line-height: 46px;
    height: 100%;
    float: left;
    cursor: pointer;
    transition: background 0.3s;
    -webkit-tap-highlight-color: transparent;

    &:hover {
      background: rgba(0, 0, 0, 0.025);
    }
  }
  .breadcrumb-container {
    float: left;
  }

  .right-menu {
    float: right;
    height: 100%;
    line-height: 50px;
    margin-right: 10px;

    &:focus {
      outline: none;
    }

    .right-menu-item {
      display: inline-block;
      padding: 0 8px;
      height: 100%;
      font-size: 18px;
      color: #5a5e66;
      vertical-align: text-bottom;

      &.hover-effect {
        cursor: pointer;
        transition: background 0.3s;

        &:hover {
          background: rgba(0, 0, 0, 0.025);
        }
      }
    }

    .avatar-container {
      position: relative;
      z-index: 10;
      margin-right: 30px;

      .avatar-wrapper {
        margin-top: 5px;
        position: relative;

        .user-avatar {
          cursor: pointer;
          width: 40px;
          height: 40px;
          border-radius: 10px;
          margin-right: 20px;
        }
        .el-icon-caret-bottom {
          cursor: pointer;
          position: absolute;
          top: 25px;
          right: 0;
        }
      }
    }
  }
}
</style>
